﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace sistemaAcademicoFinanceiroEscolas
{
    public partial class efetivarAulas : System.Web.UI.Page
    {
        public SqlConnection conexao = new SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
        public SqlCommand cmdPrincipal;
        public SqlDataReader drPrincipal;
        public string sql;

        public SqlConnection conexaoGrupo = new SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
        public SqlCommand cmdPrincipalGrupo;
        public SqlDataReader drPrincipalGrupo;
        public string sqlGrupo;

        public string efetiva;
        public string falta;
        public string observacao;

        public SqlConnection conexaoUpdate = new SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
        public SqlCommand cmdUpdate;
        public string update;

        int contador;
        int resto;



        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SqlConnection sqlc = new SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
                sqlc.Open();

                string sqlTurno = "select * from turno";

                SqlCommand cmdTurno = new SqlCommand(sqlTurno, sqlc);
                SqlDataReader myReaderTurno = cmdTurno.ExecuteReader();

                ListItem TurnoSelecione = new ListItem();

                while (myReaderTurno.Read())
                {
                    ListItem Turno = new ListItem();

                    Turno.Value = myReaderTurno["codigoTurno"].ToString();
                    Turno.Text = myReaderTurno["descricaoTurno"].ToString();

                    lstTurno.Items.Add(Turno);
                }

                cmdTurno.Dispose();
                myReaderTurno.Close();

                txtData.Text = DateTime.Now.ToString("dd/MM/yyyy");

                sqlc.Close();
            }
        }

        public void listarDisponibilidade()
        {
            Panel1.Page.Items.Clear();

            if (lstTurno.SelectedItem.Text == "Manhã")
            {
                manha();
            }
            else if (lstTurno.SelectedItem.Text == "Tarde")
            {
                tarde();
            }
            else if (lstTurno.SelectedItem.Text == "Noite")
            {
                noite();
            }
        }

        void manha()
        {
            try
            {
                conexao.Open();
                conexaoGrupo.Open();

                string conteudo = "<table width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"5\" bordercolor=\"#ffffff\">\n";
                conteudo += "<tr align=\"center\" valign=\"top\">\n\n";
                //conteudo += "<tr align=\"center\" valign=\"top\"><td class=\"td1\">\n\n";

                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '05:00') AND (horaFinalAula = '06:00')\n";


                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();


                if (drPrincipal.HasRows)
                {
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">05:00 as 06:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th1\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha01\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha11\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0506E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0506E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0506F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0506F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }

                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0506O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0506O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";

                        contador++;
                    }
                    conteudo += "</table></div>\n\n";

                    //fim de 05 as 06

                }

                drPrincipal.Close();

                conteudo += "</td>";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '06:00') AND (horaFinalAula = '07:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<td class=\"td2\">\n\n";

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">06:00 as 07:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th2\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha02\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha12\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0607E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0607E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0607F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0607F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0607O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0607O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";

                        contador++;
                    }

                    //fim 06 ás 07
                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td>";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '07:00') AND (horaFinalAula = '08:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<td class=\"td3\">\n\n";

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">07:00 as 08:00</h3>\n";

                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th3\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";


                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha03\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha13\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";

                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }


                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0708E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0708E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0708F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0708F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0708O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0708O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";

                        contador++;
                    }

                    // fim 07 as 08
                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td></tr>";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '08:00') AND (horaFinalAula = '09:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<tr align=\"center\" valign=\"top\"><td class=\"td4\">\n\n";

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">08:00 as 09:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th4\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha04\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha14\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0809E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0809E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0809F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0809F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0809O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0809O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";

                        contador++;
                    }

                    // fim 08 as 09
                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td><td class=\"td5\">\n\n";



                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '09:00') AND (horaFinalAula = '10:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">09:00 as 10:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th5\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha05\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha15\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0910E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0910E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0910F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_0910F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0910O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_0910O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";

                        contador++;
                    }

                    //fim 09 as 10
                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td><td class=\"td6\">\n\n";

                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '10:00') AND (horaFinalAula = '11:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">10:00 as 11:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th6\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";



                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha06\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha16\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1011E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1011E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1011F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1011F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1011O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1011O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";

                        contador++;
                    }

                    //fim 10 as 11
                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td></tr><tr align=\"center\" valign=\"top\"><td class=\"td7\">\n\n";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '11:00') AND (horaFinalAula = '12:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">11:00 as 12:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th7\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha07\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha17\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1112E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1112E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1112F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1112F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1112O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1112O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";

                        contador++;
                    }



                    // 11 as 12

                }



                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td></tr></table>\n";

                Panel1.Controls.Add(new LiteralControl(conteudo));


            }
            catch
            {

            }
            finally
            {
                conexao.Close();
                conexaoGrupo.Close();
            }

            //FIM MANHÃ

        }





        void tarde()
        {
            try
            {
                conexao.Open();
                conexaoGrupo.Open();

                string conteudo = "<table width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"5\" bordercolor=\"#ffffff\">\n";
                conteudo += "<tr align=\"center\" valign=\"top\"><td class=\"td1\">\n\n";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '12:00') AND (horaFinalAula = '13:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">12:00 as 13:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th1\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha01\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha11\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1213E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1213E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1213F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1213F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1213O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1213O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    //fim 12 as 13
                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                conteudo += "</td>";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '13:00') AND (horaFinalAula = '14:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<td class=\"td2\">\n\n";

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">13:00 as 14:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th2\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha02\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha12\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1314E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1314E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1314F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1314F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1314O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1314O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    // fim 13 as 14
                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                conteudo += "</td>";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '14:00') AND (horaFinalAula = '15:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<td class=\"td3\">\n\n";
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">14:00 as 15:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th3\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";


                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha03\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha13\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1415E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1415E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1415F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1415F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1415O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1415O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    //fim 14 as 15
                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                conteudo += "</td></tr>";

                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '15:00') AND (horaFinalAula = '16:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += " <tr align=\"center\" valign=\"top\"><td class=\"td4\">\n\n";
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">15:00 as 16:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th4\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha04\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha14\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1516E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1516E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1516F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1516F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1516O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1516O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    // 15 as 16
                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                conteudo += "</td>";

                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '16:00') AND (horaFinalAula = '17:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<td class=\"td5\">\n\n";

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">16:00 as 17:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th5\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha05\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha15\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1617E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1617E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1617F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1617F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1617O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1617O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    // fim 16 as 17

                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                conteudo += "</td>";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '17:00') AND (horaFinalAula = '18:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<td class=\"td6\">\n\n";
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">17:00 as 18:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th6\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha06\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha16\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1718E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1718E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1718F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1718F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1718O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1718O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }
                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td></tr></table>\n";

                Panel1.Controls.Add(new LiteralControl(conteudo));
            }
            catch
            {

            }
            finally
            {
                conexao.Close();
                conexaoGrupo.Close();
            }

            // fim 17 as 18
        }

        void noite()
        {
            try
            {
                conexao.Open();
                conexaoGrupo.Open();

                string conteudo = "<table width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"5\" bordercolor=\"#ffffff\">\n";
                conteudo += "<tr align=\"center\" valign=\"top\">";


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '18:00') AND (horaFinalAula = '19:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    //conteudo += "<td class=\"td1\">\n\n";
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">18:00 as 19:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th1\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";

                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha01\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha11\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1819E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1819E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1819F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1819F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1819O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1819O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    // fim 18 as 19

                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                //conteudo += "</td><td class=\"td2\">\n\n";




                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '19:00') AND (horaFinalAula = '20:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">19:00 as 20:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th2\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";


                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha02\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha12\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1920E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1920E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1920F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_1920F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1920O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_1920O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    // fim 19 as 20
                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                //conteudo += "</td><td class=\"td3\">\n\n";               

                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '20:00') AND (horaFinalAula = '21:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {

                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">20:00 as 21:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th3\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";



                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha03\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha13\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2021E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2021E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2021F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2021F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_2021O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_2021O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }


                    // fim 20 as 21
                }

                drPrincipal.Close();


                conteudo += "</table></div>\n\n";

                conteudo += "</td></tr><tr align=\"center\" valign=\"top\">";
                //<td class=\"td4\">\n\n";

                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '21:00') AND (horaFinalAula = '22:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">21:00 as 22:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th4\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";


                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha04\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha14\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2122E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2122E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2122F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2122F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_2122O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_2122O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    // fim 21 as 22
                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                //conteudo += "</td><td class=\"td5\">\n\n";              


                sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta, meiaHora \n";
                sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '22:00') AND (horaFinalAula = '23:00') \n";

                cmdPrincipal = new SqlCommand(sql, conexao);
                drPrincipal = cmdPrincipal.ExecuteReader();

                if (drPrincipal.HasRows)
                {
                    conteudo += "<div class=\"divisao\"><h3 class=\"horarios\">22:00 as 23:00</h3>\n";
                    conteudo += "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
                    conteudo += "<tr align=\"center\" valign=\"middle\" class=\"th5\">\n";
                    conteudo += "<th>Professor (a)</th>\n";
                    conteudo += "<th>Aluno (a) / Grupo</th>\n";
                    conteudo += "<th>Efetiva</th>\n";
                    conteudo += "<th>Falta</th>\n";
                    conteudo += "<th>Obs</th>\n";
                    conteudo += "</tr>\n";


                    while (drPrincipal.Read())
                    {
                        resto = (contador % 2);

                        if (resto == 0)
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha05\">\n";
                        }
                        else
                        {
                            conteudo += "<tr align=\"center\" valign=\"middle\" class=\"linha15\">\n";
                        }

                        conteudo += "<td>" + drPrincipal["nomeProfessor"].ToString() + "</td>\n";
                        if (drPrincipal["nomeAluno"].ToString() == "")
                        {
                            sqlGrupo = "SELECT codigoAlunoGrupo, codigoGrupo, codigoAluno, ";
                            sqlGrupo += "(SELECT nomeAluno FROM aluno WHERE (alunoGrupo.codigoAluno = aluno.codigoAluno)) AS nomeAluno ";
                            sqlGrupo += "FROM alunoGrupo where codigoGrupo = " + drPrincipal["codigoGrupo"].ToString();

                            cmdPrincipalGrupo = new SqlCommand(sqlGrupo, conexaoGrupo);
                            drPrincipalGrupo = cmdPrincipalGrupo.ExecuteReader();

                            conteudo += "<td>";

                            if (drPrincipalGrupo.HasRows)
                            {
                                while (drPrincipalGrupo.Read())
                                {
                                    conteudo += drPrincipalGrupo["nomeAluno"].ToString() + ", ";
                                }
                            }

                            conteudo += "</td>\n";
                        }
                        else
                        {
                            conteudo += "<td>" + drPrincipal["nomeAluno"].ToString() + "</td>\n";
                        }
                        if (drPrincipal["aulaRealizada"].ToString() != "False" && drPrincipal["aulaRealizada"].ToString() != "" && drPrincipal["aulaRealizada"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2223E value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2223E value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (drPrincipal["falta"].ToString() != "False" && drPrincipal["falta"].ToString() != "")
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2223F value=" + drPrincipal["codigoAula"].ToString() + " checked></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><input type=checkbox name=" + drPrincipal["codigoAula"].ToString() + "_2223F value=" + drPrincipal["codigoAula"].ToString() + "></td>\n";
                        }
                        if (Convert.ToString(drPrincipal["observacoesAula"]) != "")
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_2223O\">" + drPrincipal["observacoesAula"].ToString() + "</textarea></td>\n";
                        }
                        else
                        {
                            conteudo += "<td><textarea rows=\"2\" cols=\"10\" name=\"" + drPrincipal["codigoAula"].ToString() + "_2223O\"></textarea></td>\n";
                        }
                        conteudo += "</tr>\n";
                    }

                    // fim 22 as 23

                }

                drPrincipal.Close();

                conteudo += "</table></div>\n\n";

                conteudo += "</td></tr></table>\n";

                Panel1.Controls.Add(new LiteralControl(conteudo));
            }
            catch
            {

            }
            finally
            {
                conexao.Close();
                conexaoGrupo.Close();
            }
        }

        protected void btnVerificar_Click(object sender, EventArgs e)
        {
            listarDisponibilidade();
        }

        void listarCadastro()
        {
            if (lstTurno.SelectedItem.Text == "Manhã")
            {
                manhaSalvar();

                //mensagem java script
                string literalcc = "<script language=JavaScript>finalizar();</script>";
                Panel1.Controls.Add(new LiteralControl(literalcc));
            }
            else if (lstTurno.SelectedItem.Text == "Tarde")
            {
                tardeSalvar();

                //mensagem java script
                string literalcc = "<script language=JavaScript>finalizar();</script>";
                Panel1.Controls.Add(new LiteralControl(literalcc));
            }
            else if (lstTurno.SelectedItem.Text == "Noite")
            {
                noiteSalvar();

                //mensagem java script
                string literalcc = "<script language=JavaScript>finalizar();</script>";
                Panel1.Controls.Add(new LiteralControl(literalcc));
            }
        }

        void manhaSalvar()
        {
            try
            {
                conexao.Open();
                conexaoUpdate.Open();

                for (int i = 1; i < 8; i++)
                {
                    string horaI = "";
                    string horaF = "";
                    string hora = "";

                    switch (i)
                    {
                        case 1:
                            horaI = "05:00";
                            horaF = "06:00";
                            hora = "0506";
                            break;
                        case 2:
                            horaI = "06:00";
                            horaF = "07:00";
                            hora = "0607";
                            break;
                        case 3:
                            horaI = "07:00";
                            horaF = "08:00";
                            hora = "0708";
                            break;
                        case 4:
                            horaI = "08:00";
                            horaF = "09:00";
                            hora = "0809";
                            break;
                        case 5:
                            horaI = "09:00";
                            horaF = "10:00";
                            hora = "0910";
                            break;
                        case 6:
                            horaI = "10:00";
                            horaF = "11:00";
                            hora = "1011";
                            break;
                        case 7:
                            horaI = "11:00";
                            horaF = "12:00";
                            hora = "1112";
                            break;
                        default:
                            break;
                    }


                    sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                    sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                    sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                    sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta \n";
                    sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '" + horaI + "') AND (horaFinalAula = '" + horaF + "') \n";

                    cmdPrincipal = new SqlCommand(sql, conexao);
                    drPrincipal = cmdPrincipal.ExecuteReader();

                    if (drPrincipal.HasRows)
                    {
                        while (drPrincipal.Read())
                        {
                            foreach (string key in Request.Form.AllKeys)
                            {
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "E"))
                                {
                                    efetiva = Request.Form[key];
                                }
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "F"))
                                {
                                    falta = Request.Form[key];
                                }
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "O"))
                                {
                                    observacao = Request.Form[key];
                                }
                            }

                            if (falta != "" && falta != null)
                            {
                                falta = "1";
                            }
                            else
                            {
                                falta = "0";
                            }

                            if (efetiva != "" && efetiva != null)
                            {
                                efetiva = "1";
                            }
                            else
                            {
                                efetiva = "0";
                            }
                            update = "update aula set falta=" + falta + ", aulaRealizada=" + efetiva + ", observacoesAula='" + observacao + "' where codigoAula = " + drPrincipal["codigoAula"].ToString();

                            cmdUpdate = new SqlCommand(update, conexaoUpdate);
                            cmdUpdate.ExecuteNonQuery();

                            efetiva = "";
                            falta = "";
                            observacao = "";

                        }
                    }

                    drPrincipal.Close();
                }


            }
            catch
            {

            }
            finally
            {
                conexao.Close();
                conexaoUpdate.Close();
            }
        }

        void tardeSalvar()
        {
            try
            {
                conexao.Open();
                conexaoUpdate.Open();

                for (int i = 1; i < 7; i++)
                {
                    string horaI = "";
                    string horaF = "";
                    string hora = "";

                    switch (i)
                    {
                        case 1:
                            horaI = "12:00";
                            horaF = "13:00";
                            hora = "1213";
                            break;
                        case 2:
                            horaI = "13:00";
                            horaF = "14:00";
                            hora = "1314";
                            break;
                        case 3:
                            horaI = "14:00";
                            horaF = "15:00";
                            hora = "1415";
                            break;
                        case 4:
                            horaI = "15:00";
                            horaF = "16:00";
                            hora = "1516";
                            break;
                        case 5:
                            horaI = "16:00";
                            horaF = "17:00";
                            hora = "1617";
                            break;
                        case 6:
                            horaI = "17:00";
                            horaF = "18:00";
                            hora = "1718";
                            break;
                        default:
                            break;
                    }


                    sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                    sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                    sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                    sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta \n";
                    sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '" + horaI + "') AND (horaFinalAula = '" + horaF + "') \n";

                    cmdPrincipal = new SqlCommand(sql, conexao);
                    drPrincipal = cmdPrincipal.ExecuteReader();

                    if (drPrincipal.HasRows)
                    {
                        while (drPrincipal.Read())
                        {
                            foreach (string key in Request.Form.AllKeys)
                            {
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "E"))
                                {
                                    efetiva = Request.Form[key];
                                }
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "F"))
                                {
                                    falta = Request.Form[key];
                                }
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "O"))
                                {
                                    observacao = Request.Form[key];
                                }
                            }

                            if (falta != "" && falta != null)
                            {
                                falta = "1";
                            }
                            else
                            {
                                falta = "0";
                            }

                            if (efetiva != "" && efetiva != null)
                            {
                                efetiva = "1";
                            }
                            else
                            {
                                efetiva = "0";
                            }
                            update = "update aula set falta=" + falta + ", aulaRealizada=" + efetiva + ", observacoesAula='" + observacao + "' where codigoAula = " + drPrincipal["codigoAula"].ToString();

                            cmdUpdate = new SqlCommand(update, conexaoUpdate);
                            cmdUpdate.ExecuteNonQuery();

                            efetiva = "";
                            falta = "";
                            observacao = "";

                        }
                    }

                    drPrincipal.Close();
                }


            }
            catch
            {

            }
            finally
            {
                conexao.Close();
                conexaoUpdate.Close();
            }
        }

        void noiteSalvar()
        {
            try
            {
                conexao.Open();
                conexaoUpdate.Open();

                for (int i = 1; i < 6; i++)
                {
                    string horaI = "";
                    string horaF = "";
                    string hora = "";

                    switch (i)
                    {
                        case 1:
                            horaI = "18:00";
                            horaF = "19:00";
                            hora = "1819";
                            break;
                        case 2:
                            horaI = "19:00";
                            horaF = "20:00";
                            hora = "1920";
                            break;
                        case 3:
                            horaI = "20:00";
                            horaF = "21:00";
                            hora = "2021";
                            break;
                        case 4:
                            horaI = "21:00";
                            horaF = "22:00";
                            hora = "2122";
                            break;
                        case 5:
                            horaI = "22:00";
                            horaF = "23:00";
                            hora = "2223";
                            break;
                        default:
                            break;
                    }


                    sql = "SELECT codigoAula, codigoProfessor, (select nomeProfessor from professor where aula.codigoProfessor = professor.codigoProfessor) as nomeProfessor, \n";
                    sql += "codigoAluno, (select nomeAluno from aluno where aula.codigoAluno = aluno.codigoAluno) as nomeAluno, codigoGrupo, dataAula, horaInicialAula, \n";
                    sql += "horaFinalAula, codigoDisciplina, descricaoAssuntoAula, observacoesAula,  \n";
                    sql += "aulaRealizada, valorHora, valorTotalSemDesconto, valorTotalComDesconto, codigoAnoLetivo, falta \n";
                    sql += "FROM aula WHERE (dataAula = '" + txtData.Text + "') AND (horaInicialAula = '" + horaI + "') AND (horaFinalAula = '" + horaF + "') \n";

                    cmdPrincipal = new SqlCommand(sql, conexao);
                    drPrincipal = cmdPrincipal.ExecuteReader();

                    if (drPrincipal.HasRows)
                    {
                        while (drPrincipal.Read())
                        {
                            foreach (string key in Request.Form.AllKeys)
                            {
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "E"))
                                {
                                    efetiva = Request.Form[key];
                                }
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "F"))
                                {
                                    falta = Request.Form[key];
                                }
                                if (key.StartsWith(drPrincipal["codigoAula"].ToString() + "_" + hora + "O"))
                                {
                                    observacao = Request.Form[key];
                                }
                            }

                            if (falta != "" && falta != null)
                            {
                                falta = "1";
                            }
                            else
                            {
                                falta = "0";
                            }

                            if (efetiva != "" && efetiva != null)
                            {
                                efetiva = "1";
                            }
                            else
                            {
                                efetiva = "0";
                            }
                            update = "update aula set falta=" + falta + ", aulaRealizada=" + efetiva + ", observacoesAula='" + observacao + "' where codigoAula = " + drPrincipal["codigoAula"].ToString();

                            cmdUpdate = new SqlCommand(update, conexaoUpdate);
                            cmdUpdate.ExecuteNonQuery();

                            efetiva = "";
                            falta = "";
                            observacao = "";

                        }
                    }

                    drPrincipal.Close();
                }


            }
            catch
            {

            }
            finally
            {
                conexao.Close();
                conexaoUpdate.Close();
            }
        }

        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            listarCadastro();
            listarDisponibilidade();
        }
    }
}
